package A05_MyTressSet;

public class Student implements Comparable<Student>{
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    //compareTo底层原理为红黑树
    //this：当前要添加的元素
    //o：已经在红黑树中存在的元素
    //返回值
    //负数：说明添加元素较小，应存红黑树左边
    //正数：说明添加元素较大，应存红黑树右边
    //0：当时要添加的元素已存在，舍弃
    @Override
    public int compareTo(Student o) {
        int result = this.getAge() - o.getAge();
        return result;
    }
}
